package com.cyl.manager.act.controller;

import java.util.List;

import com.cyl.manager.act.domain.query.BatchGenerateRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;


import com.cyl.manager.act.domain.entity.FhVipExchangeCode;
import com.cyl.manager.act.domain.convert.FhVipExchangeCodeConvert;
import com.cyl.manager.act.domain.query.FhVipExchangeCodeQuery;
import com.cyl.manager.act.domain.vo.FhVipExchangeCodeVO;
import com.cyl.manager.act.service.FhVipExchangeCodeService;

import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * VIP兑换码表Controller
 *
 * @author zcc
 * @date 2025-10-09
 */
@Api(description ="VIP兑换码表接口列表")
@RestController
@RequestMapping("/act/fhVipExchangeCode")
public class FhVipExchangeCodeController extends BaseController {
    @Autowired
    private FhVipExchangeCodeService service;
    @Autowired
    private FhVipExchangeCodeConvert convert;

    @ApiOperation("查询VIP兑换码表列表")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<FhVipExchangeCode>> list(@RequestBody FhVipExchangeCodeQuery query, Pageable page) {
        List<FhVipExchangeCode> list = service.selectList(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @ApiOperation("导出VIP兑换码表列表")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:export')")
    @Log(title = "VIP兑换码表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(FhVipExchangeCodeQuery query) {
        List<FhVipExchangeCode> list = service.selectList(query, null);
        ExcelUtil<FhVipExchangeCodeVO> util = new ExcelUtil<>(FhVipExchangeCodeVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.dos2vos(list), "VIP兑换码表数据"));
    }

    @ApiOperation("获取VIP兑换码表详细信息")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<FhVipExchangeCode> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }


    @PostMapping("/batchGenerate")
    @ApiOperation("批量生成VIP充值记录")
    public ResponseEntity<Integer> batchGenerate(@RequestBody BatchGenerateRequest request) {
        service.batchGenerate(request);
        return ResponseEntity.ok(1);
    }

    @ApiOperation("新增VIP兑换码表")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:add')")
    @Log(title = "VIP兑换码表", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Integer> add(@RequestBody FhVipExchangeCode fhVipExchangeCode) {
        return ResponseEntity.ok(service.insert(fhVipExchangeCode));
    }

    @ApiOperation("修改VIP兑换码表")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:edit')")
    @Log(title = "VIP兑换码表", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody FhVipExchangeCode fhVipExchangeCode) {
        return ResponseEntity.ok(service.update(fhVipExchangeCode));
    }

    @ApiOperation("删除VIP兑换码表")
    @PreAuthorize("@ss.hasPermi('act:fhVipExchangeCode:remove')")
    @Log(title = "VIP兑换码表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
        return ResponseEntity.ok(service.deleteByIds(ids));
    }
}
